<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8' />
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <title data-i18n="resources.title_mapVLayerPolygonWGS84"></title>
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
        .mapboxgl-marker {
            width: 10px;
            height: 10px;
            background: red;
            margin-top: -5px;
            margin-left: -5px;
            border-radius: 5px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id='map'></div>
    <script type="text/javascript" include='mapbox-gl-enhance,mapv,proj4' src="../../dist/mapboxgl/include-mapboxgl.js"></script>
    <script type="text/javascript">
        var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
        var map = new mapboxgl.Map({
            container: 'map', 
            style: {
                "version": 8,
                "sources": {
                    "raster-tiles": {
                        "type": "raster",
                        "tiles": [host + '/iserver/services/map-world/rest/maps/World'],
                        "rasterSource":"iserver",
                        "tileSize": 256
                    }
                },

                "layers": [{
                    "id": "simple-tiles",
                    "type": "raster",
                    "source": "raster-tiles",
                    "minzoom": 0,
                    "maxzoom": 22
                }]
            },
            crs: mapboxgl.CRS.EPSG4326,
            center: [112.03027629538065, 22.095590365161783], 
            zoom: 6 
        });
        map.on('load', function () {
            $.get('../data/guang_dong.json', function (geojson) {
                var dataSet1 = mapv.geojson.getDataSet(geojson);
                var citys = {
                    '深圳市': 20,
                    '广州市': 40,
                    '佛山市': 60,
                    '江门市': 80,
                    '中山市': 100,
                };
                var data1 = dataSet1.get({
                    filter: function (item) {
                        if (!citys[item.name]) {
                            return false;
                        }
                        item.count = citys[item.name];
                        return true;
                    }
                });
                dataSet1 = new mapv.DataSet(data1);
                var options = {
                    gradient: {
                        0: 'yellow',
                        1: 'red'
                    },
                    globalAlpha: 0.8,
                    draw: 'intensity'
                };
                //mapboxgl.supermap.MapvLayer 构造函数的第一个 map 参数将在下个版本遗弃
                var mapVLayer1 = new mapboxgl.supermap.MapvLayer("", dataSet1, options);
                map.addLayer(mapVLayer1);

                var data2 = [];
                for (var key in citys) {
                    var center = mapv.utilCityCenter.getCenterByCityName(key.replace('市', ''));
                    data2.push({
                        geometry: {
                            type: 'Point',
                            coordinates: [center.lng, center.lat]
                        },
                        text: key
                    });
                }
                var dataSet2 = new mapv.DataSet(data2);
                var textOptions = {
                    draw: 'text',
                    font: '14px Arial',
                    fillStyle: 'blue',
                    shadowColor: 'white',
                    shadowBlue: 20,
                    zIndex: 11,
                    shadowBlur: 10
                };
                //mapboxgl.supermap.MapvLayer 构造函数的第一个 map 参数将在下个版本遗弃
                var mapVLayer2 = new mapboxgl.supermap.MapvLayer("", dataSet2, textOptions);
                map.addLayer(mapVLayer2);
            });
        });

    </script>

</body>

</html>
